package design_pattern.publish_subscribe;

public class Subscriber<M> {

    private String name;

    public Subscriber(String name) {
        this.name = name;
    }

    public void subscribe(Broker<M> broker) {
        broker.subscribe(this);
    }

    public void unSubscribe(Broker<M> broker) {
        broker.unSubscribe(this);
    }

    public void listen(String publisher, M message) {
        System.out.println(String.format("[%s] - %s 收到 %s 发来的消息：%s", Thread.currentThread().getName(), this.name, publisher, message));
    }

}
